/****************************************************
          File Name:34-6.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon 01 Sep 2014 12:24:16 PM CST
*****************************************************/

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<errno.h>

int main(int argc,char *argv[])
{
    char buf[1024];
    int j;

    for(j=0;j<argc;j++)
    {
        switch(fork())
        {
            case -1:
                exit(1);
            case 0:
                printf("orphan PID %d, PPID %d PGID %d\n",getpid(),getppid(),getpgrp());
                read(STDIN_FILENO,buf,1024);
                if(errno==EIO)
                {
                    perror("read");
                    printf("namely: EIO\n");
                    exit(1);
                }
                pause();
            default:
                break;
        }
    }

    alarm(30);
    exit(0);
}
